<?php

namespace App\Http\Controllers\Api\V1\Front\Mall;

use App\Models\CategoryProduct;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ProductController extends Controller
{
    public function category()
    {
        $category = CategoryProduct::with(['children' => function ($query) {
            $query->orderBy('sort');
        }
        ])->where('parentId', 0)
            ->orderBy('sort')->get(['categoryId', 'name']);
        return $this->apiResponse($category);
    }

    public function productList($categoryId)
    {
        $product = Product::where('categoryId', $categoryId)->get();
        return $this->apiResponse($product);
    }
}
